package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.exceptions.LyException;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {
    //根据条件查询规格参数集合
    @Override
    public List<SpecParamDTO> querySpecParams(Long categoryId, Long groupId, Boolean searching) {
        //健壮性判断，category_id和group_id不能都为空
        if(categoryId == null && groupId == null){
            // 条件不能都为空
            throw new LyException(400, "查询条件为空！请输入查询条件！");
        }
        List<SpecParam> paramList = query()
                .eq(categoryId != null,"category_id", categoryId)
                .eq(groupId != null,"group_id", groupId)
                .eq(searching != null,"searching", searching)
                .list();
        return SpecParamDTO.convertEntityList(paramList);
    }
}
